﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Globalization;
using System.Text;
using System.Windows.Forms;
using DevExpress.Data;
using DevExpress.Utils;
using DevExpress.Utils.Menu;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid;
using DevExpress.XtraGrid.Columns;
using DevExpress.XtraGrid.Views.Grid;
using DevExpress.XtraPrinting;
using ERP_RORZE_TOOL.Common.ValueObject;
using ERP_RORZE_TOOL.Tool.Reports;
using ERP_RORZE_TOOL.BizLogic;
using ERP_RORZE_TOOL.Common;

namespace ERP_RORZE_TOOL.Tool.UserControls
{
    public partial class uc_rpt_GridView : DevExpress.XtraEditors.XtraUserControl
    {
        ReportHelper helper = new ReportHelper();
        private DataTable dtMain = new DataTable();
        public GridView GridView;
        private int reportNameParent;
        private string captionParent;

        DXPopupMenu menu;

        public uc_rpt_GridView(int reportName, string caption)
        {
            InitializeComponent();
            InitDateRangeMenu();
            BindData(reportName, caption);
            ShowHideRange(reportName);

            this.dropbtDateRange.DropDownControl = menu;
            this.dropbtDateRange.Text = ToolConstants.Configuration.DateRangeTitle.SixMonths;
        }

        private void BindData(int reportName, string caption, int range = 1)
        {

            this.reportNameParent = reportName;
            this.captionParent = caption;
            switch (reportName)
            {
                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryCrosstabBorrow:
                    
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FTotalMachineAtFactory_Crosstab_Borrow);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();
                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    //gridView1.Columns["ToolID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.FLossDetails: //range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FLossDetails, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    gridView1.Columns["Date"].DisplayFormat.FormatType = FormatType.DateTime;
                    gridView1.Columns["Date"].DisplayFormat.FormatString = "dd/MM/yyyy";

                    GridColumn colQuantiy = gridView1.Columns["Quantity"];
                    colQuantiy.DisplayFormat.FormatType = FormatType.Numeric;
                    colQuantiy.DisplayFormat.FormatString = "n0";

                    //gridView1.Columns["Date"].SortOrder = ColumnSortOrder.Descending;
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.FTonKhoTongHop:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FTonKhoTongHop);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName" && column.FieldName != "FrequencyID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.Columns["Price"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["Price"].DisplayFormat.FormatString = "c2";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.FDailyBroken://range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FDailyBroken, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    gridView1.Columns["ToolID"].Visible = false;
                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "PriceJPY" || column.FieldName == "ThanhTienJPY" )
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Custom;
                    //        column.DisplayFormat.FormatString = "n2";
                    //    }

                    //    else if (column.FieldName == "TongSoLuong")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}
                    //GridColumn colTongSoLuong = gridView1.Columns["TongSoLuong"];
                    //colTongSoLuong.DisplayFormat.FormatType = FormatType.Numeric;
                    //colTongSoLuong.DisplayFormat.FormatString = "n0";

                    gridView1.Columns["TongSoLuong"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["TongSoLuong"].DisplayFormat.FormatString = "n0";

                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatType = FormatType.Custom;
                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatString = "n2";

                    gridView1.Columns["ThanhTienJPY"].DisplayFormat.FormatType = FormatType.Custom;
                    gridView1.Columns["ThanhTienJPY"].DisplayFormat.FormatString = "n2";

                    //gridView1.Columns["Date"].SortOrder = ColumnSortOrder.Descending;
                    //gridView1.Columns["ToolID"].SortOrder = ColumnSortOrder.Ascending;


                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken2CrosstabAmountUSD:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken2_CrosstabAmount_USD);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken2CrosstabQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken2_CrosstabQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    //gridView1.Columns["ToolID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMachineCrosstabAmountUSD:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Machine_CrosstabAmount_USD);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MachineID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMachineCrosstabQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Machine_CrosstabQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MachineID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenCustomer2CrosstabQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Customer2_CrosstabQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "CustomerID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    //gridView1.Columns["ToolGroupName"].DisplayFormat.FormatType = FormatType.Numeric;
                    //gridView1.Columns["ToolGroupName"].DisplayFormat.FormatString = "n0";

                    //gridView1.Columns["MachineID"].DisplayFormat.FormatType = FormatType.Numeric;
                    //gridView1.Columns["MachineID"].DisplayFormat.FormatString = "n0";

                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["CustomerID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenCustomer2CrosstabAmountUSD:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Customer2_CrosstabAmount_USD);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "CustomerID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["CustomerID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken3CrosstabToolGroupAmount:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken3_CrosstabToolGroupAmount);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken3CrosstabToolGroupQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken3_Crosstab_ToolGroupQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMaterial2CrosstabAmountUSD:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Material2_CrosstabAmount_USD);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MaterialID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["MaterialID"].SortOrder = ColumnSortOrder.Ascending;
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMaterial2CrosstabQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Material2_CrosstabQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MaterialID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["MaterialID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMistake2CrosstabAmountUSD:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Mistake2_CrosstabAmount_USD);
                    gridControl1.DataSource = dtMain;

                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["MistakeID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMistake2CrosstabQty:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyBroken_Mistake2_CrosstabQty);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolGroupName" && column.FieldName != "MistakeID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    //gridView1.Columns["ToolGroupName"].SortOrder = ColumnSortOrder.Ascending;
                    //gridView1.Columns["MistakeID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;
                case ToolConstants.Configuration.ReportName.QTotalMachineBrokenCrosstab:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QTotalMachineBroken_Crosstab);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    //gridView1.Columns["ToolID"].SortOrder = ColumnSortOrder.Ascending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.QMonthlyInStock_Query://range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyInStock_QueryWithRange, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "YearMonth" && column.FieldName != "ToolID" && column.FieldName != "Price" && column.FieldName != "Amount(JPY)" && column.FieldName != "Amount(USD)")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                        else if (column.FieldName == "Price" || column.FieldName == "Amount(JPY)")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n2";
                        }
                        else if (column.FieldName == "Amount(USD)")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "c2";
                        }
                    }
                    //gridView1.Columns["YearMonth"].SortOrder = ColumnSortOrder.Descending;

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.QMonthlyInStock://range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QMonthlyInStockWithRange, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "YearMonth" && column.FieldName != "ToolID")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                /////////////////
                /// New change 
                ////////////////////
                case ToolConstants.Configuration.ReportName.FImportDetails: //range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FImportDetailsWithRange, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "Quantity")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //    if (column.FieldName == "PriceJPY")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n2";
                    //    }
                    //}

                    gridView1.Columns["Date"].DisplayFormat.FormatType = FormatType.DateTime;
                    gridView1.Columns["Date"].DisplayFormat.FormatString = "dd/MM/yyyy";

                    gridView1.Columns["Quantity"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["Quantity"].DisplayFormat.FormatString = "n0";

                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatString = "n2";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FMonthlyImport: //range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FMonthlyImport, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "SumOfQuantity")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //    if (column.FieldName == "PriceJPY" || column.FieldName == "SumOfAmountJPY")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n2";
                    //    }
                    //}

                    gridView1.Columns["SumOfQuantity"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["SumOfQuantity"].DisplayFormat.FormatString = "n0";

                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["PriceJPY"].DisplayFormat.FormatString = "n2";

                    gridView1.Columns["SumOfAmountJPY"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["SumOfAmountJPY"].DisplayFormat.FormatString = "n2";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FUseDetails: //range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FUseDetails, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "Quantity")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}

                    gridView1.Columns["Date"].DisplayFormat.FormatType = FormatType.DateTime;
                    gridView1.Columns["Date"].DisplayFormat.FormatString = "dd/MM/yyyy";

                    gridView1.Columns["Quantity"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["Quantity"].DisplayFormat.FormatString = "n0";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FNewOldDetails:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FNewOldDetails);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "SumOfImport" || column.FieldName == "TotalNew" || column.FieldName == "TotalUse")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}
                    gridView1.Columns["SumOfImport"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["SumOfImport"].DisplayFormat.FormatString = "n0";

                    gridView1.Columns["TotalNew"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["TotalNew"].DisplayFormat.FormatString = "n0";

                    gridView1.Columns["TotalUse"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["TotalUse"].DisplayFormat.FormatString = "n0";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FBorrowDetails: //range
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FBorrowDetails, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "Quantity")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}
                    gridView1.Columns["Date"].DisplayFormat.FormatType = FormatType.DateTime;
                    gridView1.Columns["Date"].DisplayFormat.FormatString = "dd/MM/yyyy";

                    gridView1.Columns["Quantity"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["Quantity"].DisplayFormat.FormatString = "n0";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryBorrowAtPresent:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FTotalMachineAtFactory_BorrowAtPresent);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "TotalAtFactory")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}
                    gridView1.Columns["TotalAtFactory"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["TotalAtFactory"].DisplayFormat.FormatString = "n0";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryBorrow:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FQTotalMachineAtFactory_Borrow);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName == "SumOfBorrow" || column.FieldName == "SumOfReturn" || column.FieldName == "SumOfBrokenQuantity" || column.FieldName == "SumOfChangeKindBrokenQuantity" || column.FieldName == "TotalAtFactory")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.QTotalInstock1:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QTotalInstock1);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.QTotalInStockAtPresent:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.QTotalInStockAtPresent);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    foreach (GridColumn column in gridView1.Columns)
                    {
                        if (column.FieldName != "ToolID" && column.FieldName != "ToolName")
                        {
                            column.DisplayFormat.FormatType = FormatType.Numeric;
                            column.DisplayFormat.FormatString = "n0";
                        }
                    }
                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                case ToolConstants.Configuration.ReportName.FReturnDetails:
                    dtMain = helper.GetAll(ToolConstants.StoreProcedure.Report.FReturnDetails, range);
                    gridControl1.DataSource = dtMain;
                    gridView1.PopulateColumns();

                    //foreach (GridColumn column in gridView1.Columns)
                    //{
                    //    if (column.FieldName == "Quantity")
                    //    {
                    //        column.DisplayFormat.FormatType = FormatType.Numeric;
                    //        column.DisplayFormat.FormatString = "n0";
                    //    }
                    //}
                    gridView1.Columns["Date"].DisplayFormat.FormatType = FormatType.DateTime;
                    gridView1.Columns["Date"].DisplayFormat.FormatString = "dd/MM/yyyy";

                    gridView1.Columns["Quantity"].DisplayFormat.FormatType = FormatType.Numeric;
                    gridView1.Columns["Quantity"].DisplayFormat.FormatString = "n0";

                    gridView1.OptionsView.ColumnAutoWidth = false;
                    gridView1.BestFitColumns();
                    gridView1.ViewCaption = caption;
                    this.GridView = gridView1;
                    break;

                default:
                    break;

            }

        }

        private void checkboxShowFooter_CheckedChanged(object sender, EventArgs e)
        {
            if (gridView1.OptionsView.ShowFooter == true)
            {
                gridView1.OptionsView.ShowFooter = false;
            }
            else
            {
                gridView1.OptionsView.ShowFooter = true;
            }
        }

        private void ShowHideRange(int reportName)
        {

            switch (reportName)
            {
                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryCrosstabBorrow:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;

                    break;
                case ToolConstants.Configuration.ReportName.FLossDetails:
                    break;
                case ToolConstants.Configuration.ReportName.FTonKhoTongHop:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.FDailyBroken:
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken2CrosstabAmountUSD:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken2CrosstabQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMachineCrosstabAmountUSD:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMachineCrosstabQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenCustomer2CrosstabQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenCustomer2CrosstabAmountUSD:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken3CrosstabToolGroupAmount:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBroken3CrosstabToolGroupQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMaterial2CrosstabAmountUSD:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMaterial2CrosstabQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMistake2CrosstabAmountUSD:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QMonthlyBrokenMistake2CrosstabQty:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;
                case ToolConstants.Configuration.ReportName.QTotalMachineBrokenCrosstab:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.QMonthlyInStock_Query:
                    break;

                case ToolConstants.Configuration.ReportName.QMonthlyInStock:
                    break;

                /////////////////
                /// New change 
                ////////////////////
                case ToolConstants.Configuration.ReportName.FImportDetails:
                    break;

                case ToolConstants.Configuration.ReportName.FMonthlyImport:
                    break;

                case ToolConstants.Configuration.ReportName.FUseDetails:
                    break;

                case ToolConstants.Configuration.ReportName.FNewOldDetails:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.FBorrowDetails:
                    break;

                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryBorrowAtPresent:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.FTotalMachineAtFactoryBorrow:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.QTotalInstock1:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.QTotalInStockAtPresent:
                    dropbtDateRange.Visible = false;
                    lbLine.Visible = false;
                    lbRange.Visible = false;
                    break;

                case ToolConstants.Configuration.ReportName.FReturnDetails:
                    break;

                default:
                    break;

            }

        }

        protected virtual void InitDateRangeMenu()
        {
            menu = new DXPopupMenu();
            menu.Items.Add(new DXMenuItem(ToolConstants.Configuration.DateRangeTitle.SixMonths, new EventHandler(OnItemClick6Months), null, null, null, null));
            menu.Items.Add(new DXMenuItem(ToolConstants.Configuration.DateRangeTitle.OneYear, new EventHandler(OnItemClick1Year), null, null, null, null));
            menu.Items.Add(new DXMenuItem(ToolConstants.Configuration.DateRangeTitle.TwoYears, new EventHandler(OnItemClick2Years), null, null, null, null));
            menu.Items.Add(new DXMenuItem(ToolConstants.Configuration.DateRangeTitle.AllTime, new EventHandler(OnItemClickAllTime), null, null, null, null));

        }

        void OnItemClick6Months(object sender, EventArgs e)
        {
            BindData(this.reportNameParent, this.captionParent, 1);
            dropbtDateRange.Text = ToolConstants.Configuration.DateRangeTitle.SixMonths;
        }

        void OnItemClick1Year(object sender, EventArgs e)
        {
            BindData(this.reportNameParent, this.captionParent, 2);
            dropbtDateRange.Text = ToolConstants.Configuration.DateRangeTitle.OneYear;
        }

        void OnItemClick2Years(object sender, EventArgs e)
        {
            BindData(this.reportNameParent, this.captionParent, 3);
            dropbtDateRange.Text = ToolConstants.Configuration.DateRangeTitle.TwoYears;
        }

        void OnItemClickAllTime(object sender, EventArgs e)
        {
            BindData(this.reportNameParent, this.captionParent, 0);
            dropbtDateRange.Text = ToolConstants.Configuration.DateRangeTitle.AllTime;
        }
    }
}
